import hilog from '@ohos.hilog';
import promptAction from '@ohos.promptAction';
export default {
    data: {
        title: "",
        text:"",
        index:null,
        todos:[{id:0,text:'hello',done:false}]
    },
    onInit() {
        this.title = "Hello World";
    },

    textChange(e){
        // console.log(e.text)
        this.text = e.text
    },
    addTodo(){
        console.log("addTodo-11")

        let text = this.text;
        if(text){
            this.todos.push({
                id:Math.random().toString(16).slice(2),
                text:this.text,
                done:false
            })

            this.text = ""
        }
    },
    delTodo(index){
        this.index = index;
        this.$element('dialogId').show()
    },
    confirmClick(){
        console.log("確定",this.index)
        if(this.index != null){
            this.todos.splice(this.index,1)
            this.$element('dialogId').close()

            promptAction.showToast({
                message: '刪除成功！'
            })

        }

    },
    cancelClick(){
        this.$element('dialogId').close()
    }
}
